<template>
  <div class="app-container">
    <el-form label-width="120px">
      <el-form-item label="会员等级">
      </el-form-item>
      <el-form-item label="名称">
        <el-input style="width: 200px"  v-model="level.name"/>
      </el-form-item>
      <el-form-item label="价格">
        <el-input style="width: 200px"  v-model="level.price"/>
      </el-form-item>
      <el-form-item label="折扣">
        <span>
          <el-input style="width: 200px" v-model="level.discountPercent"></el-input>%
        </span>

      </el-form-item>
      <el-form-item>
        <el-button :disabled="saveBtnDisabled" type="primary" @click="edit">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import level from "../../../api/level";
  export default {
    data(){
      return{
        level:{
          sex: ""
        },
        saveBtnDisabled:false,
        dialogVisible: false,
      }
    },
    created() {
      if(this.$route.params!=null&&this.$route.params.id!=null){
        this.queryById(this.$route.params.id);
      }
    },
    methods: {
      edit(){
        this.level.discount=this.level.discountPercent/100;
        if(this.$route.params!=null&&this.$route.params.id!=null){
          level.modify(this.level).then(res=>{
            this.$message.success(res.message)
            this.$router.push({path:`/account/level`})
          })
        }else{
          level.add(this.level).then(res=>{
            this.$message.success(res.message)
            this.$router.push({path:`/account/level`})
          })
        }
        },
      queryById(id){
        level.getById(id).then(res=>{
          this.level = res.data
          this.level.discountPercent=this.level.discount*100
        })
      },
      handleInputConfirm() {
        let inputValue = this.inputValue;
        if (inputValue) {
          this.dynamicTags.push(inputValue);
        }
        this.inputVisible = false;
        this.inputValue = '';
      },
    }

  }
</script>
<style>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }

  .el-tag + .el-tag {
    margin-left: 10px;
  }
  .button-new-tag {
    margin-left: 10px;
    height: 32px;
    line-height: 30px;
    padding-top: 0;
    padding-bottom: 0;
  }
  .input-new-tag {
    width: 90px;
    margin-left: 10px;
    vertical-align: bottom;
  }
</style>
